﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views {
    import flash.events.*;
    import org.robotlegs.core.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.views.components.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;

    public class ConstructionSiteMediator extends Mediator implements IMediator {

        public var constructionSite:ConstructionSite;
        public var tutorialModel:TutorialModel;
        public var userModel:UserModel;
        public var roomSlotsModel:RoomSlotsModel;

        override public function onRegister():void{
            eventMap.mapListener(eventDispatcher, EventConstants.CREATE_ROOM_VIEW, this.roomViewCreated);
            eventMap.mapListener(eventDispatcher, GameEvent.TUTORIAL_STATE_CHANGE, this.createFirstShovel);
            this.constructionSite.addEventListener(ViewCompEvent.CLICK, this.createRoom);
            if (this.userModel.level >= 2){
                this.createBuildRoomButtonFirstFloor(GameConstants.TYPE_RECEPTION, 1);
            };
        }
        private function createFirstShovel(_arg1:Event):void{
            if (this.tutorialModel.state == TutorialModel.LEVEL1_BUILD_RECEPTION){
                eventMap.unmapListener(eventDispatcher, GameEvent.TUTORIAL_STATE_CHANGE, this.createFirstShovel);
                this.createBuildRoomButtonFirstFloor(GameConstants.TYPE_RECEPTION, 1);
            };
        }
        private function createBuildRoomButtonFirstFloor(_arg1:String, _arg2:int):void{
            var _local3:Slot = this.roomSlotsModel.getSlotById(_arg2);
            this.constructionSite.createBuildRoomButtons(_arg1, _local3.position.x, _local3.position.y);
        }
        private function createBuildRoomButtonSecondFloor(_arg1:String, _arg2:int):void{
            var _local3:Slot = this.roomSlotsModel.getSlotById(_arg2);
            this.constructionSite.createBuildRoomButtons(_arg1, _local3.position.x, (_local3.position.y - 130));
        }
        private function createRoom(_arg1:ViewCompEvent):void{
            var _local2:String = _arg1.sender;
            l(("i event.sender: " + _local2));
            this.constructionSite.removeRoomButton(_local2);
            var _local3:Object = {};
            _local3[GameConstants.TYPE_RECEPTION] = 1;
            _local3[GameConstants.TYPE_WAITING_ROOM] = 2;
            _local3[GameConstants.TYPE_BATTERY_ROOM] = 8;
            _local3[GameConstants.TYPE_TREATMENT_GENERAL] = 7;
            var _local4:int = _local3[_local2];
            if (_local4){
                dispatch(new InfoEvent(EventConstants.LOAD_ROOM, null, {room_type:_local2, slot:_local4}));
            };
        }
        private function roomViewCreated(_arg1:InfoEvent):void{
            var _local2:IRoom;
            if (this.roomSlotsModel.getNumberOfOccupiedSlots() < 6){
                _local2 = (_arg1.info as IRoom);
                if (_local2){
                    switch (_local2.type){
                        case GameConstants.TYPE_RECEPTION:
                            this.createBuildRoomButtonFirstFloor(GameConstants.TYPE_WAITING_ROOM, 2);
                            break;
                        case GameConstants.TYPE_WAITING_ROOM:
                            this.createBuildRoomButtonSecondFloor(GameConstants.TYPE_BATTERY_ROOM, 8);
                            break;
                        case GameConstants.TYPE_BATTERY_ROOM:
                            this.createBuildRoomButtonSecondFloor(GameConstants.TYPE_TREATMENT_GENERAL, 7);
                            break;
                    };
                };
            };
        }

    }
}//package net.wooga.pets.views 
